#ifndef TREE_H
#define TREE_H

#include "Mesh.h"
#include "Leaves.h"
#include "PSFire.h"
#include "FireObject.h"

class Tree : public Mesh, public FireObject
{	
	public:

		Tree();
		virtual ~Tree();
		void init(const char* filename, ID3D11Device* g_device, ID3D11DeviceContext* g_context);
	
		void draw(const Camera& camera, const vector<Light*>& lights);
		virtual void draw(int subset, ID3DX11Effect* fx, const char* technique) const;

		void Update(float dt);

		Leaves& getLeaves() { return _leaves; }

		void stepFire() { }
		void setDiscard() { }

		void drawFire(CXMMATRIX mVP, const XMFLOAT4& pos, float dt);

		void sproutLeaves();
		void catchFire();

		void endFire();
		void dropLeaves();

		void startFog();
		void reset();
		
		void changeRenderMode();

		void generateEmitters(UINT subset, UINT global_ID, ID3DX11Effect* fxDefault, const char* techDefault);
		XMFLOAT4X4 getSubsetMatrix(UINT subset) const;
	private:

		bool bFire;

		bool bLeaves;


		float counter;
		bool bFog;

		
		enum  {	NonTexturedNonLitWireframe, NonTexturedFlatShaded, NonTexturedSmoothShaded, 
							TexturedSmoothShaded, DisplacementMapping };
		unsigned int render_mode;
		
		static const int NUM_RENDER_MODES = 5;
		
		//////////////////////////

		Leaves _leaves;
		
		ID3DX11EffectMatrixVariable* fx_m_World;
		ID3DX11EffectMatrixVariable* fx_m_WorldViewProj;
		
		ID3DX11EffectMatrixVariable*			fx_m_L_ViewProj;
		ID3DX11EffectShaderResourceVariable*	fx_tex_shadow_map;
		ID3DX11EffectVariable*					fx_lights;

		ID3DX11EffectScalarVariable*	fx_num_lights;

		ID3DX11EffectVectorVariable*	fx_pEye;
		ID3DX11EffectScalarVariable*	fx_bShadowed;
		ID3DX11EffectScalarVariable*	fx_bUsePCSS;

		ID3D11ShaderResourceView*		srv_heightmap;
		ID3D11ShaderResourceView*		srv_sand;

};


#endif